import java.net.*;
import java.util.*;

import com.google.common.net.*;

public class Url2Lds {
	private String domain;
	private String url;
	private ArrayList<InternetDomainName> lds;
	private InternetDomainName idn;
	
	public Url2Lds(String urlString) throws MalformedURLException{
		this.url = urlString;
		this.lds = new ArrayList<InternetDomainName>();
		generateLds();
	}
	private void generateDomain() throws MalformedURLException{
		this.domain = (new URL(url)).getHost();
	}
	private void generateIdn() throws MalformedURLException{
		generateDomain();
		this.idn = InternetDomainName.from(this.domain);
	}
	private void generateLds() {
		try {
			generateIdn();
			
			InternetDomainName tld = this.idn.publicSuffix();
			int size = this.idn.parts().size()-tld.parts().size()+1;			
			this.lds.add(tld);
			
			List<String> parts = this.idn.parts().reverse();
			for(int i = 1;i < size;i++){
				this.lds.add(this.lds.get(i-1).child(parts.get(this.lds.get(i-1).parts().size())));
			}
			
		} catch (MalformedURLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	public String get(int index){
		return this.lds.get(index).name();
	}
	public int size(){
		return this.lds.size();
	}
	public static void main(String args[]) throws MalformedURLException{
		Url2Lds u = new Url2Lds("http://docs.guava-libraries.googlecode.com.cn/git/javadoc/com/google/common/net/InternetDomainName.html#from(java.lang.String)");
		System.out.println((u.size())+u.get(u.size()-1));
	}
	
	
}
